using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.VisualBasic.CompilerServices;

namespace Deloitte.Windows.Forms
{
    public partial class FormatExcelCellsForm : Form
    {
        private string xlNumberFormat;
        public FormatExcelCellsForm()
        {
            InitializeComponent();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            //todo: convert this code
            try
            {
                string text1 = this.lsNumberTypes.SelectedItem.ToString().Trim().ToUpper();
                bool flag1 = false;
                if (this.ck1000.Checked)
                {
                    flag1 = true;
                }
                string text5 = text1;
                if (StringType.StrCmp(text5, "GENERAL", false) == 0)
                {
                    this.XLNumberFormat = "General";
                }
                else
                {
                    int num1;
                    string text2=null;
                    if (StringType.StrCmp(text5, "NUMBER", false) == 0)
                    {
                        this.XLNumberFormat = "0";
                        if (flag1)
                        {
                            this.XLNumberFormat = "#,##" + this.XLNumberFormat;
                        }
                        this.DecimalPlaces();
                        num1 = 0;
                        do
                        {
                            if (this.lvNumber.Items[num1].Selected)
                            {
                                text2 = this.lvNumber.Items[num1].Text.ToString().Trim();
                            }
                            num1++;
                        }
                        while (num1 <= 3);
                        string text4 = text2;
                        if (StringType.StrCmp(text4, "-1234.10", false) != 0)
                        {
                            if (StringType.StrCmp(text4, "1234.10", false) == 0)
                            {
                                this.XLNumberFormat = this.XLNumberFormat + ";[Red]";
                                if (flag1)
                                {
                                    this.XLNumberFormat = this.XLNumberFormat + "#,##0";
                                }
                                else
                                {
                                    this.XLNumberFormat = this.XLNumberFormat + "0";
                                }
                                this.DecimalPlaces();
                            }
                            else if (StringType.StrCmp(text4, "(1234.10)", false) == 0)
                            {
                                if (this.lvNumber.Items[3].Selected)
                                {
                                    this.XLNumberFormat = this.XLNumberFormat + "_);[Red](";
                                    if (flag1)
                                    {
                                        this.XLNumberFormat = this.XLNumberFormat + "#,##0";
                                    }
                                    else
                                    {
                                        this.XLNumberFormat = this.XLNumberFormat + "0";
                                    }
                                }
                                else
                                {
                                    this.XLNumberFormat = this.XLNumberFormat + "_);(";
                                    if (flag1)
                                    {
                                        this.XLNumberFormat = this.XLNumberFormat + "#,##0";
                                    }
                                    else
                                    {
                                        this.XLNumberFormat = this.XLNumberFormat + "0";
                                    }
                                }
                                this.DecimalPlaces();
                                this.XLNumberFormat = this.XLNumberFormat + ")";
                            }
                        }
                    }
                    else if (StringType.StrCmp(text5, "CURRENCY", false) == 0)
                    {
                        this.XLNumberFormat = "0";
                        this.XLNumberFormat = "$#,##" + this.XLNumberFormat;
                        this.DecimalPlaces();
                        num1 = 0;
                        do
                        {
                            if (this.lvCurrency.Items[num1].Selected)
                            {
                                text2 = this.lvCurrency.Items[num1].Text.ToString().Trim();
                            }
                            num1++;
                        }
                        while (num1 <= 3);
                        string text3 = text2;
                        if (StringType.StrCmp(text3, "-$1,234.10", false) != 0)
                        {
                            if (StringType.StrCmp(text3, "$1,234.10", false) == 0)
                            {
                                this.XLNumberFormat = this.XLNumberFormat + ";[Red]";
                                this.XLNumberFormat = this.XLNumberFormat + "$#,##0";
                                this.DecimalPlaces();
                            }
                            else if (StringType.StrCmp(text3, "($1,234.10)", false) == 0)
                            {
                                if (this.lvNumber.Items[3].Selected)
                                {
                                    this.XLNumberFormat = this.XLNumberFormat + "_);[Red](";
                                    this.XLNumberFormat = this.XLNumberFormat + "$#,##0";
                                }
                                else
                                {
                                    this.XLNumberFormat = this.XLNumberFormat + "_);(";
                                    this.XLNumberFormat = this.XLNumberFormat + "$#,##0";
                                }
                                this.DecimalPlaces();
                                this.XLNumberFormat = this.XLNumberFormat + ")";
                            }
                        }
                    }
                    else if (StringType.StrCmp(text5, "DATE", false) == 0)
                    {
                        int num2 = this.lvDates.Items.Count;
                        int num4 = num2 - 1;
                        num1 = 0;
                        while (num1 <= num4)
                        {
                            if (this.lvDates.Items[num1].Selected)
                            {
                                break;
                            }
                            num1++;
                        }
                        switch (num1)
                        {
                            case 0:
                                {
                                    this.XLNumberFormat = "m/d/yyyy";
                                    goto Label_0549;
                                }
                            case 1:
                                {
                                    this.XLNumberFormat = "m/d;@";
                                    goto Label_0549;
                                }
                            case 2:
                                {
                                    this.XLNumberFormat = "m/d/yy;@";
                                    goto Label_0549;
                                }
                            case 3:
                                {
                                    this.XLNumberFormat = "mm/dd/yy;@";
                                    goto Label_0549;
                                }
                            case 4:
                                {
                                    this.XLNumberFormat = "[$-409]d-mmm;@";
                                    goto Label_0549;
                                }
                            case 5:
                                {
                                    this.XLNumberFormat = "[$-409]d-mmm-yy;@";
                                    goto Label_0549;
                                }
                            case 6:
                                {
                                    this.XLNumberFormat = "[$-409]mmm-yy;@";
                                    goto Label_0549;
                                }
                            case 7:
                                {
                                    this.XLNumberFormat = "[$-409]mmmm-yy;@";
                                    goto Label_0549;
                                }
                            case 8:
                                {
                                    this.XLNumberFormat = "[$-409]mmmm d, yyyy;@";
                                    goto Label_0549;
                                }
                            case 9:
                                {
                                    this.XLNumberFormat = "m/d/yyyy;@";
                                    goto Label_0549;
                                }
                            case 10:
                                {
                                    this.XLNumberFormat = "[$-409]d-mmm-yyyy;@";
                                    goto Label_0549;
                                }
                        }
                    }
                    else if (StringType.StrCmp(text5, "TEXT", false) == 0)
                    {
                        this.XLNumberFormat = "@";
                    }
                    else
                    {
                        this.XLNumberFormat = "@";
                    }
                }
            Label_0549:
                this.Hide();
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception exception2)
            {
                ProjectData.SetProjectError(exception2);
                Exception exception1 = exception2;
                this.XLNumberFormat = "@";
                ProjectData.ClearProjectError();
            }

        }
        public string XLNumberFormat
        {
            get
            {
                return this.xlNumberFormat;
            }
            set
            {
                this.xlNumberFormat = value;
            }
        }
        public void DecimalPlaces()
        {
            int num1 = Convert.ToInt32(this.decUpDown.Value);
            if (num1 > 0)
            {
                this.xlNumberFormat = this.xlNumberFormat + ".";
                int num3 = num1 - 1;
                for (int num2 = 0; num2 <= num3; num2++)
                {
                    this.xlNumberFormat = this.xlNumberFormat + "0";
                }
            }
        }

        private void lsNumberTypes_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.lvNumber.Visible = false;
            this.lvCurrency.Visible = false;
            this.lvDates.Visible = false;
            this.lblNegative.Visible = false;
            this.ck1000.Visible = false;
            string text1 = this.lsNumberTypes.SelectedItem.ToString().ToUpper();
            if (StringType.StrCmp(text1, "GENERAL", false) == 0)
            {
                this.decUpDown.Visible = false;
                this.lblDec.Visible = false;
                this.ck1000.Visible = false;
                this.lblComment.Text = "General format cell have no specific number format.";
            }
            else if (StringType.StrCmp(text1, "NUMBER", false) == 0)
            {
                this.decUpDown.Visible = true;
                this.lblDec.Visible = true;
                this.lblNegative.Visible = true;
                this.ck1000.Visible = true;
                this.lvNumber.Visible = true;
                this.lblComment.Text = "Number is used for general display of numbers.\x00a0 Currency offers specialized formatting for monetary value.";
            }
            else if (StringType.StrCmp(text1, "CURRENCY", false) == 0)
            {
                this.decUpDown.Visible = true;
                this.ck1000.Visible = false;
                this.lblDec.Visible = true;
                this.lvCurrency.Visible = true;
                this.lblComment.Text = "Currency formats are used for general monetary values.";
            }
            else if (StringType.StrCmp(text1, "DATE", false) == 0)
            {
                this.decUpDown.Visible = false;
                this.ck1000.Visible = false;
                this.lblDec.Visible = false;
                this.lvDates.Visible = true;
                this.lblComment.Text = "Date formats display date and time serial numbers as date values.\x00a0 Except for items that have an asterisk(*), applied formats do not switch date orders with the operating system.";
            }
            else if (StringType.StrCmp(text1, "TIME", false) == 0)
            {
                this.ck1000.Visible = false;
                this.lblComment.Text = "Time formats display date and time serial numbers as date values.\x00a0 Except for items that have an asterisk(*), applied formats do not switch time orders with the operating system.";
            }
            else if (StringType.StrCmp(text1, "TEXT", false) == 0)
            {
                this.ck1000.Visible = false;
                this.decUpDown.Visible = false;
                this.lblDec.Visible = false;
                this.lblComment.Text = "Text format cells are treated as text even when a number is in the cell.\x00a0 The cell is displayed exactly as entered.";
            }

        }

 

    }

}